<template>
	<view class="likePage">
		<view class="likeWrap">
			<view class="likeItemWrap" v-for="(like,index) in likeConfig.list">
				<view class="btm">
					<image class="img" :style="{width:`100%`}" mode="aspectFill" :src="like.cover ? like.cover : '/static/images/common/placeholderImg.png'"></image>
					<view class="workName">
						<view class="name textHide">{{like.name}}</view>
						<view class="isLike" @click.stop="onClickLike(like,index)">
							<u-icon class="icon" size="18" color="#bf8fef" name="heart-fill"></u-icon>{{$util.bigNumberTransform(like.likeCount)}}
						</view>
					</view>
				</view>	
			</view>
		</view>
		<u-empty :show="likeConfig.total == 0 && likeConfig.list.length == 0" mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png" />
		<template v-if="likeConfig.total != 0">
			<u-loadmore :status="likeConfig.loadStatus" />
		</template>
	</view>
</template>

<script>
	import {mapActions} from 'vuex';
	export default {
		data() {
			return {
				likeConfig:{
					list: [],
					page: 1,
					pages: 0,
					limit: 10,
					loading: false,
					loadStatus: 'loadmore',
				}
			};
		},
		onLoad(){
			this._queryLikeList();
		},
		onReachBottom() {
			this._queryLikeList(true);
		},
		onPullDownRefresh(){
			uni.startPullDownRefresh();
			this.initListConfig();
			this._queryLikeList();
		},
		methods:{
			...mapActions('user',['queryLikeList']),
			...mapActions("follow", ["follow", "cancelFollow","cancelLike","like"]),
			onClickLike(item,index){
				console.log(item);
				if(this.likeConfig.list[index].loading) return;
				this.likeConfig.list[index].loading = true
				this.cancelLike({id: item.galleryId}).then(res => {
					item.isLike = !item.isLike;
					item.likeCount -= 1;
					this.likeConfig.list.splice(index,1);
				}).finally(()=>{
					this.likeConfig.list[index].loading =false;
				})
			},
			_queryLikeList(ReachBtm){
				if (this.likeConfig.loading || this.likeConfig.loadStatus == "nomore") return false;
				this.likeConfig.loading = true;
				this.likeConfig.loadStatus = "loading";
				if (ReachBtm) this.likeConfig.page++;
				this.queryLikeList({
					limit: this.likeConfig.limit,
					page: this.likeConfig.page,
				}).then(res => {
					res.rows.map(item=>{item.loading=false});
					this.likeConfig.list = this.likeConfig.list.concat(res.rows);
					this.likeConfig.pages = res.pages;
					this.likeConfig.total = res.total;
					this.likeConfig.loadStatus = this.likeConfig.page >= this.likeConfig.pages ? "nomore" : "loadmore";
				}).finally(() => {
					this.likeConfig.loading = false;
					uni.stopPullDownRefresh();
				})
			},
			initListConfig() {
				this.likeConfig.page = 1;
				this.likeConfig.total = -1;
				this.likeConfig.pages = 0;
				this.likeConfig.list = [];
				this.likeConfig.loading = false;
				this.likeConfig.loadStatus = "loadmore";
			},
		}
	}
</script>

<style lang="scss">
.likePage{
	padding: 30rpx;
	.likeWrap{
		display: flex;
		flex-direction:row;
		flex-wrap: wrap;
		.likeItemWrap{
			margin-bottom: 60rpx;
			// height: 650rpx;
			width: 100%;
			border-radius: 10rpx;
			border:1px solid rgba(200, 200, 200, 0.3);
			background-color: #0a0a22;
			box-sizing: border-box;
			display: flex;
			flex-direction:column;
			padding: 30rpx;
			.topView{
				width: 100%;
				display: flex;
				.userInfor{
					flex: 1;
					padding:0 20rpx ;
					overflow: hidden;
				}
				.user{
					flex: 1;
					overflow: hidden;
				}
			}
			.btm{
				.workName{
					margin-top: 20rpx;
					display: flex;
					justify-content: space-between;
					.name{
						flex: 1;
					}
					.isLike{
						display: flex;
						.icon{
							margin-right: 12rpx;
							color: #fff;
						}
					}
				}
			}
			.infor{
				color: #999;
				font-size: 24rpx;
				-webkit-line-clamp: 2; //行数需设置
				line-clamp: 2;
				margin: 30rpx 0;
				min-height: 64rpx;
			}
			.felxWrap{
				display: flex;
				justify-content: space-between;
				align-items: center;
			}
			.avatarWrap{
				position: relative;
				.authIcon{
					position: absolute;
					bottom: -10rpx;
					right: -10rpx;
				}
			}
			
			.text{
				margin-bottom: 10rpx;
				color: #999;
				font-size: 26rpx;
			}
			.time{
				font-size: 24rpx;
			}
			.number{
				margin-top:20rpx;
			}
			.nickName{
				color: #fff;
				font-weight: bold;
				width: 100%;
				box-sizing: border-box;
			}
			.follow {
				color: #bf8fef;
				border: 2rpx solid #bf8fef;
				width: 160rpx;
				// margin: 30rpx auto 0;
				padding: 12rpx 0;
				border-radius: 50rpx;
				font-size: 24rpx;
				font-weight: bold;
				text-align: center;
			}
			.cancel {
				color: #999999;
				border: 2rpx solid #999999;
			}
		}
	}
}
</style>
